package leetcode;

import javax.swing.tree.TreeNode;

/**
 * 对称二叉树
 */
public class Solution6 {
    public boolean isSymmetric(TreeNode root) {
        return  compare(root.left,root.right);
    }

    public boolean compare(TreeNode left,TreeNode right){
        if(left == null && right != null){
            return false;
        }
        if(left != null && right == null){
            return false;
        }
        if(left == null && right == null){
            return true;
        }
        if(left.val != right.val){
            return false;
        }
        //是左右孩子相等的情况
        boolean outside = compare(left.left,right.right);
        boolean inside = compare(left.right,right.left);

        return outside && inside;
    }
}
